//
//  TKYSafetyMaterialCell.m
//  StationHouseHelper
//
//  Created by apple on 2018/7/2.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYSafetyMaterialCell.h"
@interface TKYSafetyMaterialCell()

@end

@implementation TKYSafetyMaterialCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.selectedBtn];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.deleteButton];

        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        __weak typeof(self) weakSelf = self;
        [weakSelf.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).with.offset(kWidthScale *20);
            make.top.equalTo(weakSelf.contentView).with.offset(kHeightScale *12);
//            make.bottom.equalTo(self.contentView).with.offset(-12);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *100);
        }];
        
        
        [weakSelf.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(weakSelf.contentView).with.offset(kHeightScale *12);
            make.right.equalTo(weakSelf.contentView).with.offset(-kWidthScale *20);
//            make.bottom.equalTo(self.contentView).with.offset(-12);

            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *80);
        }];
        
        [weakSelf.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(weakSelf.titleLabel.mas_bottom).with.offset(kHeightScale *2);
            make.left.equalTo(weakSelf.contentView).with.offset(kWidthScale *20);
            make.bottom.equalTo(weakSelf.contentView).with.offset(0);
            make.height.mas_equalTo(kHeightScale *40);
            make.width.mas_equalTo(kWidthScale *200);
        }];
//
        [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(self.selectedBtn.mas_bottom).with.offset(kHeightScale *2);
            make.right.equalTo(self.contentView).with.offset(-kWidthScale *20);
           // make.bottom.equalTo(self.contentView).with.offset(-12);

            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
    }
    return self;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"资料关联";
        _titleLabel.font = Font(14);
    }
    return _titleLabel;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.font = Font(14);
        _contentLabel.numberOfLines = 0;
        //_contentLabel.backgroundColor = [UIColor redColor];
       // _contentLabel.text = @"dsdff.docdsdff.docdsdff.docdsdff.dsdff.docdsdff.docdsdff.docdsdff.docdsdff.doc";
    }
    return _contentLabel;
}



- (UIButton *)selectedBtn{
    if (_selectedBtn == nil) {
        _selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //[_selectedBtn setTitle:@"" forState:UIControlStateNormal];
        //_selectedBtn.backgroundColor = [UIColor redColor];
        
        [_selectedBtn setTitle:@"请关联模型" forState:UIControlStateNormal];
        [_selectedBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _selectedBtn.titleLabel.font = Font(14);
        [_selectedBtn addTarget:self action:@selector(selectButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectedBtn;
}

- (UIButton *)deleteButton{
    if (_deleteButton == nil) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteButton.titleLabel.font = Font(14);
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(deleteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

- (void)selectButtonClick:(UIButton *)button{
    if (self.seletetedButtonBlock) {
        self.seletetedButtonBlock(button);
    }
    NSLog(@"点击了选择按钮");
}


- (void)deleteButtonClick:(UIButton *)button{
    if (self.deleteButtonBlock) {
        self.deleteButtonBlock(button);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
